var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    checkword: "",
    findArr: [],
    searchlist: [],
    resultif:false,
  },

  getSearch: function (e) {
    var that = this;
    var keywords = e.detail.value;
    app.util.request({
      'url': 'entry/wxapp/jiansuo.yisheng_keywordssearch',
      'data':{
        keywords:keywords
      },
      success: function (res) {
        console.log(res.data)
        if(res.data.length>0){
          that.setData({
            checkword: keywords,
            resultif: false,
            searchlisttip:res.data
          })
        }else{
          that.setData({
            checkword: keywords,
            resultif: true,
          })
          app.util.request({
            'url': 'entry/wxapp/jiansuo.addsearch',
            'data':{
              openid: wx.getStorageSync('openid'),
              checkword:keywords,
              source:1,
            },
          })
          that.getSearchlist();
        }
        
      },
    })

  },
  listitembtn(e) {
    var that = this;
    var checkword = e.currentTarget.dataset.checkword;
    app.util.request({
      'url': 'entry/wxapp/jiansuo.addsearch',
      'data':{
        openid: wx.getStorageSync('openid'),
        checkword:checkword,
        source:1,
      },
    })
    that.setData({
      resultif: true,
      checkword:checkword,
    })
    that.getSearchlist()
  },

  searchHistory:function(e){
    var that = this;
    var checkword = e.currentTarget.dataset.checkword;
    app.util.request({
      'url': 'entry/wxapp/jiansuo.addsearch',
      'data':{
        openid: wx.getStorageSync('openid'),
        checkword:checkword,
        source:1,
      },
    })
    that.setData({
      resultif: true,
      checkword:checkword,
    })
    that.getSearchlist()
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    that.getHotsearch();
  },
  getHotsearch:function(){
    var that = this;
    app.util.request({
      'url': 'entry/wxapp/jiansuo.show_hotsearch',
      'data':{
        source:1
      },
      success: function (res) {
        that.setData({
          findArr:res.data
        })
      },
    })
  },
  getSearchlist:function(){
    var that = this;
    app.util.request({
      'url': 'entry/wxapp/jiansuo.searchlist',
      'data':{
        openid:wx.getStorageSync('openid'),
        checkword:that.data.checkword,
        source:1,
        sindex:1,
      },
      success: function (res) {
        that.setData({
          zhuanjialist:res.data.zhuanjialist,
        })
      },
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },
  doctoritem(e){
    var zid = e.currentTarget.dataset.zid;
    wx.navigateTo({
      url: '/hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye?zid='+zid,
    })
  },
  /**  hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})